﻿// <copyright file="VisibleIfTrueConverter.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-03-03</date>
// <summary>Converts a true to Visible, false to Collapsed</summary>

namespace NYTimes.ValueConverters
{
    using System;
    using System.Windows;
    using System.Windows.Data;

    /// <summary>
    /// converter to return visible if the value is true, collapsed if false.
    /// </summary>
    public class VisibleIfTrueConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// if value = true, then visible, otherwise collapsed
        /// </summary>
        /// <param name="value">true or false</param>
        /// <param name="targetType">Visibility enumeration</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>Visibility.Visible or Visibilty.Collapsed</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return Visibility.Collapsed;
            }

            bool show = (bool)value;

            if (show)
            {
                return Visibility.Visible;
            }

            return Visibility.Collapsed;
        }

        /// <summary>
        /// Modifies the target data before passing it to the source object. This method is called only in TwoWay bindings. 
        /// </summary>
        /// <param name="value">The target data being passed to the source.</param>
        /// <param name="targetType">The Type of data expected by the source object.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic. </param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>The value to be passed to the source object.</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
